import React from 'react';
import { Switch, Route, Redirect, routerRedux } from 'dva/router'
import PropTypes from 'prop-types'
import dynamic from 'dva/dynamic'
import App from './routes/app';

const { ConnectedRouter } = routerRedux

const Routers = function ({ history, app }) {
  const error = dynamic({
    app,
    // component: () => import('./routes/error/'),
  })
  // 基础中心
  const basic=[
     // 卖家——订单列表
    {
      path: '/sell/orderList',
      component: () => import('./routes/sell/order'),
      models: () => [import('./models/sell/order')],
    },
    // 卖家——订单详情
    {
      path: '/sell/orderDetail',
      component: () => import('./routes/sell/order/orderDetail'),
      // models: () => [import('./models/sell/order/orderDetail')],
    },
     // 买家——订单列表
    {
      path: '/buy/orderList',
      component: () => import('./routes/buy/order'),
      models: () => [import('./models/buy/order')],
    },
  ]
  const routes = basic;
  return (
    <ConnectedRouter history={history}>
      <App>
        <Switch>
          <Route exact path="/" render={() => (<Redirect to="/sell/orderList" />)} />
          {
            routes.map(({ path, ...dynamics }, key) => (
              <Route key={key}
                exact
                path={path}
                component={dynamic({
                  app,
                  ...dynamics,
                })}
              />
            ))
          }
          <Route component={error} />
        </Switch>
      </App>
    </ConnectedRouter>
  )

}

Routers.propTypes = {
  history: PropTypes.object,
  app: PropTypes.object,
}

export default Routers
